package com.xzy.web.controller;

import com.xzy.custom.Page;
import com.xzy.custom.ResultMap;
import com.xzy.entities.BorrowRecord;
import com.xzy.service.BorrowRecordService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * TODO
 *
 * @author XiangZhongyi
 * ClassName: BorrowContraller
 * date: 2022/1/24 12:58
 */
@Controller
@RequestMapping("/borrow")
public class BorrowContraller {

    @Autowired
    private BorrowRecordService borrowRecordService;

    @RequestMapping("/information")
    public String information(){
        return "admin/borrow/manage";
    }

    @RequestMapping("/findAllBorrow")
    @ResponseBody
    public ResultMap<List<BorrowRecord>> findAllBookType(Page page, @RequestParam("limit")int limit,@Param("name")String name){
        page.setRows(limit);
        page.setPage((page.getPage()-1)*limit);
        Integer total = borrowRecordService.findBorrowCount(page,name);
        List<BorrowRecord> list = borrowRecordService.findAllBorrow(page,name);
        return new ResultMap<List<BorrowRecord>>("",list,0,total);
    }
}
